package com.warren.blog.testkafaka;

import org.apache.kafka.clients.producer.Partitioner;
import org.apache.kafka.common.Cluster;

import java.util.Map;

/**
 * @author warren
 * @data: 2022/3/29 10:20 PM
 * @decription:
 */
public class MyPartitionner implements Partitioner {
    @Override
    public int partition(String s, Object o, byte[] bytes, Object o1, byte[] bytes1, Cluster cluster) {
        //获取数据
        String msgValues = o1.toString();
        int partition;
        if (msgValues.contains("warren")) {
            partition = 0;
        }  else {
            partition = 1;
        }
        return partition;
    }

    @Override
    public void close() {

    }

    @Override
    public void configure(Map<String, ?> map) {

    }
}
